/**
 *      Copyright 2008 Augusto Campos <b>augcampos&#64augcampos.pt></b><br>
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 3 of the License.
 *      <p>
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      <p>
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
package com.augcampos.gui;

import com.augcampos.core.n501070324_Intervencao;
import com.augcampos.core.n501070324_Intervencoes;
import com.augcampos.core.n501070324_PedidoSuporteFormacao;
import com.augcampos.core.n501070324_PedidoSuporteSistema;
import com.augcampos.core.n501070324_PedidosAssistencia;
import com.augcampos.core.n501070324_Pessoas;
import com.augcampos.core.n501070324_PostoTrabalho;
import com.augcampos.core.n501070324_PostosTrabalho;
import com.augcampos.core.n501070324_Tecnico;
import com.augcampos.core.n501070324_Utilizador;
import java.util.Date;
import java.util.Random;

/**
 *
 * @author Augusto Campos <b>augcampos@augcampos.pt</b>
 */
public class n501070324_MDIForm extends javax.swing.JFrame {

    n501070324_Pessoas ps = new n501070324_Pessoas();
    n501070324_PostosTrabalho pt = new n501070324_PostosTrabalho();
    n501070324_PedidosAssistencia pa = new n501070324_PedidosAssistencia();
    n501070324_Intervencoes in = new n501070324_Intervencoes();

    /** Creates new form n501070324_MDIForm */
    public n501070324_MDIForm() {
        initComponents();

        openMenuItemActionPerformed(null); // load all data on startup
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        rndDataMenu = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        exitMenuItem = new javax.swing.JMenuItem();
        tablesMenu = new javax.swing.JMenu();
        usersMenu = new javax.swing.JMenuItem();
        tecnicsMenu = new javax.swing.JMenuItem();
        worlstationsMenu = new javax.swing.JMenuItem();
        suportRequestMenu = new javax.swing.JMenuItem();
        interventionsMenu = new javax.swing.JMenuItem();
        infMenu = new javax.swing.JMenu();
        statisticsMenu = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        desktopPane.setDoubleBuffered(true);

        fileMenu.setText("Ficheiro");

        openMenuItem.setText("Abrir");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);

        saveMenuItem.setText("Gravar");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveMenuItem);
        fileMenu.add(jSeparator1);

        rndDataMenu.setText("Gerar Dados de Teste");
        rndDataMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rndDataMenuActionPerformed(evt);
            }
        });
        fileMenu.add(rndDataMenu);
        fileMenu.add(jSeparator2);

        exitMenuItem.setText("Sair");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        tablesMenu.setText("Tabelas");

        usersMenu.setText("Utilizadores");
        usersMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usersMenuActionPerformed(evt);
            }
        });
        tablesMenu.add(usersMenu);

        tecnicsMenu.setText("Tecnicos");
        tecnicsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tecnicsMenuActionPerformed(evt);
            }
        });
        tablesMenu.add(tecnicsMenu);

        worlstationsMenu.setText("Postos de Trabalho");
        worlstationsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                worlstationsMenuActionPerformed(evt);
            }
        });
        tablesMenu.add(worlstationsMenu);

        suportRequestMenu.setText("Pedidos Suporte");
        suportRequestMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                suportRequestMenuActionPerformed(evt);
            }
        });
        tablesMenu.add(suportRequestMenu);

        interventionsMenu.setText("Intervenções");
        interventionsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                interventionsMenuActionPerformed(evt);
            }
        });
        tablesMenu.add(interventionsMenu);

        menuBar.add(tablesMenu);

        infMenu.setText("Informação");

        statisticsMenu.setText("Estatisticas");
        statisticsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                statisticsMenuActionPerformed(evt);
            }
        });
        infMenu.add(statisticsMenu);

        menuBar.add(infMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void usersMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usersMenuActionPerformed
        n501070324_UserForm us = new n501070324_UserForm(ps);
        us.setVisible(true);
        desktopPane.add(us);
    }//GEN-LAST:event_usersMenuActionPerformed

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        ps.load();
        pt.load();
        pa.load();
        in.load();
    }//GEN-LAST:event_openMenuItemActionPerformed

    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        in.save();
        pa.save();
        pt.save();
        ps.save();
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void tecnicsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tecnicsMenuActionPerformed
        n501070324_TecnicsForm tn = new n501070324_TecnicsForm(ps);
        tn.setVisible(true);
        desktopPane.add(tn);
    }//GEN-LAST:event_tecnicsMenuActionPerformed

    private void worlstationsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_worlstationsMenuActionPerformed
        n501070324_WorkstationsForm ws = new n501070324_WorkstationsForm(pt);
        ws.setVisible(true);
        desktopPane.add(ws);
    }//GEN-LAST:event_worlstationsMenuActionPerformed

    private void suportRequestMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_suportRequestMenuActionPerformed
        n501070324_SuportRequestForm sr = new n501070324_SuportRequestForm(pa, ps, pt, in);
        sr.setVisible(true);
        desktopPane.add(sr);
    }//GEN-LAST:event_suportRequestMenuActionPerformed

    private void interventionsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_interventionsMenuActionPerformed
        n501070324_InterventionForm ii = new n501070324_InterventionForm(in, ps, pa);
        ii.setVisible(true);
        desktopPane.add(ii);
    }//GEN-LAST:event_interventionsMenuActionPerformed

    private void statisticsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_statisticsMenuActionPerformed
        n501070324_StatiticsForm sf = new n501070324_StatiticsForm(pa, in);
        sf.setVisible(true);
        desktopPane.add(sf);
    }//GEN-LAST:event_statisticsMenuActionPerformed

    private void rndDataMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rndDataMenuActionPerformed
        n501070324_Pessoas lps = new n501070324_Pessoas();
        n501070324_PostosTrabalho lpt = new n501070324_PostosTrabalho();
        n501070324_PedidosAssistencia lpa = new n501070324_PedidosAssistencia();
        n501070324_Intervencoes lin = new n501070324_Intervencoes();

        Random rnd = new Random();

        for (int i = 0; i < 50; i++) {
            n501070324_Utilizador u = new n501070324_Utilizador();
            u.setNumero(i);
            u.setNome("Utilizador" + i);
            lps.add(u);

            n501070324_Tecnico t = new n501070324_Tecnico();
            t.setNumero(i);
            t.setNome("Tecnico" + i);
            lps.add(t);


            n501070324_PostoTrabalho p = new n501070324_PostoTrabalho();
            p.setNumero(i);
            p.setDescricao("PT" + i);
            p.setCpu("CPU" + i);
            p.setDisco("" + (80 * rnd.nextInt(5000)) + "Gb");
            lpt.add(p);


            n501070324_PedidoSuporteFormacao psf = new n501070324_PedidoSuporteFormacao();
            psf.setTema("TEMA" + i);
            psf.setData(new Date(108,rnd.nextInt(12)+1,rnd.nextInt(29)+1));
            psf.setUtilizador(u.getNumero());
            lpa.add(psf);

            n501070324_PedidoSuporteSistema pss = new n501070324_PedidoSuporteSistema();
            pss.setDescricao("DESC" + i);
            pss.setData(new Date(108,rnd.nextInt(12)+1,rnd.nextInt(29)+1));
            pss.setUtilizador(u.getNumero());
            pss.setPostoTrabalho(p.getNumero());
            lpa.add(pss);


            for (int j = 0; j < rnd.nextInt(10) + 1; j++) {
                n501070324_Intervencao i1 = new n501070324_Intervencao();
                i1.setPedidoSuporte(psf.getNumero());
                i1.setDescricao("DESC " + i + " " + j);
                i1.setData(new Date(108,rnd.nextInt(12)+1,rnd.nextInt(29)+1));
                i1.setTecnico(t.getNumero());
                i1.setDuracao(rnd.nextInt(20)+1);
                i1.setResolvido((rnd.nextInt(10) % 2) == 0 ? true : false);
                lin.add(i1);
            }
            for (int j = 0; j < rnd.nextInt(10) + 1; j++) {
                n501070324_Intervencao i1 = new n501070324_Intervencao();
                i1.setPedidoSuporte(pss.getNumero());
                i1.setDescricao("DESC " + i + " " + j);
                i1.setData(new Date(108,rnd.nextInt(12)+1,rnd.nextInt(29)+1));
                i1.setTecnico(t.getNumero());
                i1.setDuracao(rnd.nextInt(20)+1);
                i1.setResolvido((rnd.nextInt(10) % 3) == 0 ? true : false);
                lin.add(i1);
            }

        }

        lps.save();
        lpt.save();
        lpa.save();
        lin.save();
    }//GEN-LAST:event_rndDataMenuActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                n501070324_MDIForm mdi = new n501070324_MDIForm();

                mdi.setVisible(true);
                mdi.setExtendedState(n501070324_MDIForm.MAXIMIZED_BOTH);
                mdi.invalidate();

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu infMenu;
    private javax.swing.JMenuItem interventionsMenu;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem rndDataMenu;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JMenuItem statisticsMenu;
    private javax.swing.JMenuItem suportRequestMenu;
    private javax.swing.JMenu tablesMenu;
    private javax.swing.JMenuItem tecnicsMenu;
    private javax.swing.JMenuItem usersMenu;
    private javax.swing.JMenuItem worlstationsMenu;
    // End of variables declaration//GEN-END:variables
}
